tools/xenpmd: fix possible '\0' truncation
authorMarek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Thu, 5 Apr 2018 01:50:53 +0000 (03:50 +0200)
committerWei Liu <wei.liu2@citrix.com>
Fri, 6 Apr 2018 08:05:56 +0000 (09:05 +0100)
commit938c8f53b1f80175c6f7a1399efdb984abb0cb8b
treee1e7a65e02862dc498dcaf0adbf6ba0d1bb0f1d9
parent27751d89248c8c5eef6d8b56eb8f7d2084145080
tools/xenpmd: fix possible '\0' truncation

gcc-8 complains:
    xenpmd.c:207:9: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation]
             strncpy(info->oem_info, attrib_value, 32);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    xenpmd.c:201:9: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation]
             strncpy(info->battery_type, attrib_value, 32);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    xenpmd.c:195:9: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation]
             strncpy(info->serial_number, attrib_value, 32);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    xenpmd.c:189:9: error: 'strncpy' specified bound 32 equals destination size [-Werror=stringop-truncation]
             strncpy(info->model_number, attrib_value, 32);
             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Copy 31 chars, then make sure terminating '\0' is present. Those fields
are passed to strlen and as '%s' for snprintf later.

Signed-off-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Acked-by: Wei Liu <wei.liu2@citrix.com>
Release-Acked-by: Juergen Gross <jgross@suse.com>
tools/xenpmd/xenpmd.c